//
//  HZTabBc.swift
//  weibo002
//
//  Created by 黑眼圈 on 16/4/16.
//  Copyright © 2016年 heiyan. All rights reserved.
//

import UIKit

class HZTabBc: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()


        
        //添加子控制
        addChildViewController()
        
        
        //修改 tabbar 为自定义的
        let tabbar = HZTabBar()
//        self.tabBar = tabbar
        //KVC赋值
        setValue(tabbar, forKey: "tabBar")
        
        
        //执行闭包
        tabbar.addBtn = { [weak self] in
            
//            print("阿飞飞飞飞")
            
            let addView = HZAddView()
            
            //设置和屏幕一样宽
            addView.frame = UIScreen.mainScreen().bounds
            
        
            
            //添加加号按钮的 view
            self?.view.addSubview(addView)
            
                addView.show(self)
            
            
            
        }
        
    }
    
 
    
    
    //添加所有子控制器
    func addChildViewController() {
        
        addChildViewController(HZHomeTc(), imgName: "tabbar_home", titltName: "首页")
        addChildViewController(HZMessageTc(), imgName: "tabbar_message_center", titltName: "消息")
        addChildViewController(HZDiscoverTc(), imgName: "tabbar_discover", titltName: "发现")
        addChildViewController(HZProfileTc(), imgName: "tabbar_profile", titltName: "我")
    }
    
    
    //添加子控制器
    func addChildViewController(vc:UITableViewController,imgName:String,titltName:String) {
        
        //设置便签的文字和图片
        vc.title = titltName
        
        //设置文字的颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        
        vc.tabBarItem.image = UIImage(named: imgName)
        
        //设置选中图片并不被图片渲染
        var img = UIImage(named: "\(imgName)_selected")
        img = img?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        vc.tabBarItem.selectedImage = img
        
        //添加到标题控制器中去
        addChildViewController(UINavigationController(rootViewController: vc))
        
    }
    
    

}




